package gui

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/layout"
	"fyne.io/fyne/v2/widget"
)

// 打开添加窗口
func (ui *MainWindow) categoryWindow(win fyne.Window, types string) func() {
	return func() {

		w := fyne.CurrentApp().NewWindow(types)

		w.SetFixedSize(true) // 设置固定大小，避免用户拖动改变大小

		// w.Minimizable = false // 去掉最小化按钮
		// w.SetMaximizable(false)

		name := widget.NewLabel("name: ")
		nameInput := widget.NewEntry()
		nameInput.SetPlaceHolder("请输入公司名称+小程序名称")
		//多行输入
		nameInput.MultiLine = true
		nameInput.Wrapping = 2 // 开启自动换行
		nameRow := container.NewBorder(nil, nil, name, nil, nameInput)

		appid := widget.NewLabel("appid:")
		appidText := widget.NewEntry()
		appidText.SetPlaceHolder("请输入抖音小程序appid")
		//多行输入
		appidText.MultiLine = true
		appidText.Wrapping = 2 // 开启自动换行
		appidRow := container.NewBorder(nil, nil, appid, nil, appidText)

		saveBtn := widget.NewButton(" 保存 ", func() {})

		cancelBtn := widget.NewButton(" 取消 ", func() {
			w.Close()
		})

		saveBtn.OnTapped = func() {

		}

		btnLayout := container.New(layout.NewHBoxLayout(), saveBtn, cancelBtn)
		saveBtnLayout := container.NewBorder(nil, nil, nil, btnLayout, nil)

		buttonnLayout := container.NewBorder(nil, nil, nil, nil, saveBtnLayout)
		bodyLayout := container.NewBorder(nameRow, nil, nil, nil, appidRow)
		// addDataLayout := container.New(layout.NewVBoxLayout(), bodyLayout, buttonnLayout)
		addDataLayout := container.NewBorder(bodyLayout, buttonnLayout, nil, layout.NewSpacer(), nil)
		w.SetContent(addDataLayout)

		// start 监听主窗口的关闭事件
		// 前提是必须设置主窗口
		w.SetOnClosed(func() {
			w.Close()
		})
		// edn 监听主窗口的关闭事件

		// 设置窗口大小,
		w.Resize(fyne.NewSize(400, 200))
		w.CenterOnScreen()
		w.Show()
	}
}
